package com.teach.servlet.web2;

import java.io.IOException;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.teach.commons.RequestUtil;

import com.teach.entity.News;
import com.teach.service.NewsService;
import com.teach.service.impl.NewsServiceImpl;

@WebServlet("/web2/news-update.s")
public class NewsUpdateServlet extends HttpServlet {

	private NewsService service = new NewsServiceImpl();
	private Logger log = LoggerFactory.getLogger(getClass());
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		News news = null;
		//News news = RequestUtil.loadParams(request, News.class);
		//log.debug("修改参数：{}",JSON.toJSONString(news));
		
//		String msg = "ok";
//		try {
//			String newsId = request.getParameter("newsId");
//			news=service.get(newsId);
//		}catch (Exception e) {
//			msg = e.getMessage();
//			news=null;
//		}
		String newsId = request.getParameter("newsId");
		
		//System.out.println(newsId+"我来到这里啦就哈吉"+JSON.toJSONString(news));
		response.reset();
		response.setContentType("text/json;charset=UTF-8");
		response.getWriter().print(JSON.toJSONString(service.get(newsId)));
		response.flushBuffer();
	}
}
